<?php
/*
 * 手机客户端 学生列表
 * 2013-12-04
 */
 
include "inc/public_header.php";
include "inc/MiniaturePro.class.php";
include "func/user.php";				//用户信息处理函数
include "func/pic.php";					//图片处理函数


$reJson = array(); //构建返回值
$reJson["success"]='1';


//页数，第一页为0
$page			= $_REQUEST["page"]; 
//每页记录数			
$pagesize		= $_REQUEST["pagesize"];

//每页记录数			
$zpuid		= $_REQUEST["id"];

//图片地址
$IMG_DEFAULT_PATH = "http://www.chinalaohu.com/images/news/";

//头像根路径
$LOGO_BASE_PATH = "http://www.chinalaohu.com/modules/miniature.php?w=150&h=150&p=/uploads/zjl_ilogo/";

//头像根路径
$PIC_BASE_PATH = "http://www.chinalaohu.com/img1/uploads/zjl_ilogo/";

//默认头像
$LOGO_DEFAULT_PATH = "http://www.chinalaohu.com/images/zjl/logo.png";

if(!isset($page)){
	$page = 0;
}
if(!isset($pagesize)){
	$pagesize = 10; //默认每页10条
}

//作品总数
$sql="  select 
			count(0) as zp_ct
		from 
			new_weituo_zuopin a 
			INNER JOIN new_weituo_person b on a.uid=b.uid
		where
			a.uid='".$zpuid ."'
			and a.aflag='1'
			and a.dr='0'
";
$db->query($sql);
$db->next_record();
$reJson["count"] = $db->f("zp_ct");

$imgWidth = '200';
//作品信息列表
$sql ="select 
				a.id
				,a.aname
				,a.czln
				,a.pingfen
				,a.img_path
				,a.img_id
				,f.ct as zan_count
				,a.aflag
				,g.ct as pl_count
				,e.id as mini_img_id
				,e.awidth as mini_img_width
				,e.aheight as mini_img_height
				,e.aname as mini_img_aname
				,h.ct as gz_count
		from 
				new_weituo_zuopin a	
				left join new_weituo_person d on a.uid=d.uid
				left join new_weituo_pic_size e on a.img_id=e.img_id and e.awidth='".$imgWidth."'
				left join (select count(0) as ct,zpid from new_weituo_pingfen where zan='1' group by zpid) f on a.id=f.zpid
				left join (select count(0) as ct,zpid from new_weituo_comment where dr='0' group by zpid) g on a.id=g.zpid
				left join (select count(0) as ct,zpid from new_weituo_gz group by zpid) h on a.id=h.zpid
		where
				a.dr='0'
				and a.uid='".$zpuid."'
				and a.aflag='1'
		";
$sql = $sql."GROUP BY id limit ".($page * $pagesize).",".$pagesize;
$db->query($sql);
$worksArr = array();
$miniature = new MiniaturePro();	//构建缩略图处理类

while($db->next_record()){
	//处理生成缩略图
	$imgInfos = pic_resize(
							 $miniature
							,$db->f("img_path")
							,$db->f("mini_img_aname")
							,$imgWidth
							,$db->f("img_id")
							,$db->f("mini_img_id")
							,$db->f("mini_img_width")
							,$db->f("mini_img_height"));
	$imgUrl = "";
	if($imgInfos["success"]!="0"){
		$imgUrl = $imgInfos["mini_img_url"];
	}
	if($db->f("czln")){
		$czln=$db->f("czln");
	}else{
		$czln="未填写";
	}
	$worksArr[] = array(
		
		"worksId"=>$db->f("id")								//作品id
		,"imgUrl"=>$imgUrl				//图片
		,"worksName"=>$db->f("aname")							//作品名称
		//,"imgWidth"=>(string)$imgInfos["mini_img_width"]	//图片宽度
		//,"imgHeight"=>(string)$imgInfos["mini_img_height"]	//图片高度

	);
}
$reJson["list"]=$worksArr;


$sql="select a.nickname,a.ilogo_path,b.aname,a.uid,a.picture,a.grsm,a.realname,a.honor,a.school_honor,a.zhuanye,a.year,a.hobby,a.email
from new_weituo_person a 
LEFT JOIN new_weituo_xuexiao b on a.xuexiao_id=b.id
where a.uid='".$zpuid."'";
$db->query($sql);
//echo $sql;
while($db->next_record()){
	if(!$db->f("picture")){
		$bigImg=$LOGO_DEFAULT_PATH;
		$img=$LOGO_DEFAULT_PATH;
	}else{
		$bigImg=$PIC_BASE_PATH.$db->f("picture");
		$img=$LOGO_BASE_PATH.$db->f("picture");
	}
	
		$reJson["name"]=(string)$db->f("realname");
		//,"nickname"=>(string)$db->f("nickname")
		//,"id"=>$db->f("uid")
		$reJson["userIcon"]=$img;
		//,"bigImgUrl"=>$bigImg
		$reJson["college"]=(string)$db->f("aname");
		//,"picture"=>(string)$IMG_DEFAULT_PATH.$db->f("picture");
		$info = array();
		$base="";

		if($db->f("year")){
			$base=$base."入学年份：".$db->f("year");

		}
		if($db->f("zhuanye")){
			$base=$base."\n专　　业：".$db->f("zhuanye");

		}
		if($db->f("email")){
			$base=$base."\n邮　　箱：".$db->f("email");

		}
		if($db->f("hobby")){
			$base=$base."\n爱　　好：".$db->f("hobby");

		}
		//echo $hobby;
		//echo $base;
			$info[] = array(
				"title"=>"基本信息"
				,"detail"=>(string)$base
			);
		/**/
		if($db->f("grsm")){
			$info[] = array(
				"title"=>"自我介绍"
				,"detail"=>$db->f("grsm")
			);
		}
		if($db->f("honor")){
			$info[] = array(
				"title"=>"获得荣誉"
				,"detail"=>$db->f("honor")
			);
		}
		if($db->f("school_honor")){
			$info[] = array(
				"title"=>"其他荣誉"
				,"detail"=>$db->f("school_honor")
			);
		}
		$reJson["info"]=$info;
		
}
/****/
echo json_encode($reJson);
 ?>